package main

import "fmt"

// Go supports anonymous functions, which can form closures
// Anonymous functions are useful when you want to define a
// function inline without having to name it

// function intSeq return another function, which we define
// anonymously in the body of intSeq.
// The returned function closes over the variable i to form a closure
func intSeq() func() int {
	i := 0
	return func() int {
		i++
		return i
	}
}

func main() {
	nextInt := intSeq()

	// update each time we call nextInt
	fmt.Println(nextInt())
	fmt.Println(nextInt())
	fmt.Println(nextInt())

	newInts := intSeq()
	fmt.Println(newInts())
}
